<?php

namespace app\common\business;

use app\common\model\mysql\SysNotice as SysNoticeModel;

class SysNotice
{
    public $noticeObj = null;
    public function __construct()
    {
        $this->noticeObj = new SysNoticeModel();
    }
    //查询岗位列表
    public function getNormalNotice($where,$field,$limit,$page){
        $noticeData = $this->noticeObj->getNormalNoticeList($where,$field,$limit,$page);
        if(!$noticeData){
            return [];
        }
        $noticeData = $noticeData->toArray();
        return $noticeData;
    }

    //添加
    public function addNotice($data){
        try {
            $this->noticeObj->save($data);
        }catch (\Exception $e){
            throw new \think\Exception($e->getMessage());
        }
        return $this->noticeObj->id;
    }

    //根据$id,去数据库查询是否存在这条记录
    public function getNoticeById($id){
        $user = $this->noticeObj->getNoticeByNoticeId($id);
        if(!$user){
            return [];
        }
        return $user->toArray();
    }

    /**
     * 根据主键id更新数据表中的数据
     * @param $id
     * @param $data
     * @return bool
     */
    public function updateById($id,$data){
        $id = intval($id);
        if(empty($id) || empty($data) || !is_array($data)){
            return false;
        }
        $where = [
            "notice_id"=>$id,
        ];
        return $this->noticeObj->where($where)->find()->save($data);
    }

    //根据$ids数组，删除数据库记录delete
    public function DelNoticeIds($ids){
        $ids = explode(',', $ids);
        $result = $this->noticeObj->DelNoticeIds($ids);
        return $result;
    }
}
